//
//  EqpInfoViewController.m
//  Hive
//
//  Created by 惠俊贝 on 15/9/3.
//  Copyright (c) 2015年 ZM. All rights reserved.
//

#import "EqpInfoViewController.h"
#import "EqpInfo.h"
#import "DateUtils.h"
#import "CarIDViewController.h"
@interface EqpInfoViewController () <UITableViewDataSource, UITableViewDelegate> {
    
    __weak IBOutlet UILabel *eqpNameLabel;
    __weak IBOutlet UILabel *carIDLabel;
    __weak IBOutlet UILabel *addressLabel;
    __weak IBOutlet UITableView *tableview;
    
    NSArray *cellNames;
    NSArray *valueArray;
}

@end

@implementation EqpInfoViewController
@synthesize eqpInfo;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    backButton.hidden = NO;
    
    cellNames = @[@"当前车辆报警信息",
                  @"当前车辆违章查询",
                  @"电话号码",
                  @"设备IMEI",
                  @"产品类型",
                  @"开始日期",
                  @"到期日期"];
    
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    NSString *simNum = eqpInfo.SimNum == nil ? @"":eqpInfo.SimNum;
    NSString *IMEI = eqpInfo.IMEI == nil ? @"":eqpInfo.IMEI;
    NSString *Type = eqpInfo.Type == nil ? @"":eqpInfo.Type;
    NSString *ValidFrom = eqpInfo.ValidFrom == nil ? @"":eqpInfo.ValidFrom;
    NSString *ValidEnd = eqpInfo.ValidEnd == nil ? @"":eqpInfo.ValidEnd;
    if (![ValidFrom isEqualToString:@""]) {
        ValidFrom = [DateUtils dataFromString:ValidFrom fromFormat:@"yyyy-MM-dd'T'hh:mm:ss" toFormat:@"yyyy年MM月dd日"];
    }
    if (![ValidEnd isEqualToString:@""]) {
        ValidEnd = [DateUtils dataFromString:ValidEnd fromFormat:@"yyyy-MM-dd'T'hh:mm:ss" toFormat:@"yyyy年MM月dd日"];
    }
    valueArray = @[@"",
                   @"",
                   simNum,
                   IMEI,
                   Type,
                   ValidFrom,
                   ValidEnd];
    
    NSString *eqpName = eqpInfo.EqpName == nil ? @"":eqpInfo.EqpName;
    NSString *carNumber = eqpInfo.CarNumber==nil ? @"":eqpInfo.CarNumber;
    NSString *address = eqpInfo.Address==nil ? @"暂无":eqpInfo.Address;
    
    titleLabel.text = eqpName;
    eqpNameLabel.text = [NSString stringWithFormat:@"设备名称：%@",eqpName];
    carIDLabel.text = [NSString stringWithFormat:@"车牌号：%@",carNumber];
    addressLabel.text = [NSString stringWithFormat:@"位置：%@",address];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)carIdButtonPress:(id)sender {
    CarIDViewController *toController = [[CarIDViewController alloc] initWithNibName:@"CarIDViewController" bundle:nil];
    [self.navigationController pushViewController:toController animated:YES];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return cellNames.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        cell.textLabel.text = [cellNames objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = [valueArray objectAtIndex:indexPath.row];
        if (indexPath.row < 2) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else {
            cell.userInteractionEnabled = NO;
        }
    }
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selected = NO;
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
